﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cos.Core.NHibernate;
using Cos.Core.NHibernate.Tests;
using NUnit.Framework;

namespace Cos.Module.Security.NHibernate.Tests
{
    public class ModuleFixtureBase : FixtureBase
    {
        public CultureDataModel culture;
        public AccountDataModel account;
        public RoleReferenceDataModel role;
        public NavDataModel nav;
        public TemplateDataModel template;
        public PermissionDataModel permission;


        public ModuleFixtureBase()
            : base(new TestModel())
        {
            this.culture = new CultureDataModel
            {
                Id = "fr-CA",
                CultureDesc = string.Empty,
                IsDefault = true
            };

            this.account = new AccountDataModel
            {
                AccountName = "account name",
                IsSystem = true,
            };

            this.role = new RoleReferenceDataModel
            {
                RoleName = "role"
            };

            this.template = new TemplateDataModel
            {
                IsListView = false,
                TemplateName = "Template",
                TemplateUrl = "url"
            };

            this.nav = new NavDataModel
            {
                InheritPermissions = true,
                NavOrder = 1,
                ParentId = 0,
                TemplateId = this.template.Id
            };

            this.permission = new PermissionDataModel { PermissionName = "ReadOnly" };
        }

        [TestFixtureSetUp]
        public void ModuleSetupContext()
        {
            using (var tx = this.Session.BeginTransaction())
            {
                this.Session.SaveOrUpdate(this.culture);
                this.Session.SaveOrUpdate(this.account);
                this.Session.SaveOrUpdate(this.role);
                this.Session.SaveOrUpdate(this.nav);
                this.Session.SaveOrUpdate(this.template);
                this.Session.SaveOrUpdate(this.permission);

                tx.Commit();
            }

            this.Session.Flush();
            this.Session.Clear();
        }
    }
}
